﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace web_search
{
    internal class DaoAdmin
    {
        SqlConnection sc;//数据库连接对象sssssssss
        public SqlConnection connect() {  //连接数据库
            string str = @"Data Source=192.168.186.1,54345;Initial Catalog=BookManageSysytem;User ID=BookAdmin;Password=admin123;";
            sc = new SqlConnection(str);
            sc.Open();
            return sc; 
        }
        public SqlCommand command(string sql) //执行一条sql语句
        {
            SqlCommand cmd = new SqlCommand(sql,connect());
            return cmd;
        }
        public int Execute(string sql) //获取执行sql语句后，数据库表中数据条数的更新数量
        {
            return command(sql).ExecuteNonQuery();
        }

        public SqlDataReader read(string sql) //读取数据库的数据
        {
            return command(sql).ExecuteReader();
        }
        public void DaoClose() //关闭数据库连接
        {
            sc.Close();
        }
    }
}
